package com.hliushi.state.example01_right;

/**
 * @author: hliushi
 * @date: 2023/2/15 22:47
 **/
public class TrafficLight {


    private State state = new RedLight(); // 初始化为红灯

    public void switchToGreen() {
        state.switchToGreen(this);
        this.currentState();
    }

    public void switchToRed() {
        state.switchToRed(this);
        this.currentState();
    }

    public void switchToYellow() {
        state.switchToYellow(this);
        this.currentState();
    }

    public void currentState() {
        // System.out.printf("当前交通路灯为 : %s \n", state.getClass().getSimpleName());
        System.out.printf("当前交通路灯为 : %s \n", state.currentState());
    }

    public void setState(State state) {
        this.state = state;
    }
}
